(function(factory) {
    "use strict";
    if(typeof(window)!=='object' || !window.document) throw new Error("需要一个包含document的window");
    if (typeof require === "function" && typeof module === "object" && typeof module.exports === "object"){
        module.exports = factory(require('s94-web'));
    } else {
        window['vue_component_'] = factory(window['s94']);
    }
})(function($){
    "use strict";
    return {
        props: ['list','num','speed'],
        emits: ['change'],
        data(){
            return {
				this_num: this.num || 1,
				index:0,
				runtime: this.speed || 1000,
				backing: false,
				nexting: false,
				runing: false,
			}
        },
        template: `<ul class="loop_dom_outer" :class="{backing:backing, nexting:nexting}">
		<li class="li-front"><slot :row="show_list.front"></slot></li>
		<li v-for="(row,i) in show_list.list" :class="'li-'+i"><slot :row="row"></slot></li>
		<li class="li-after"><slot :row="show_list.after"></slot></li>
	</ul>`,
        methods: {
			back(){
				if(this.runing) return;
				let app = this, count = this.list.length;
				this.backing = true;
				this.runing = setTimeout(() => {
					app.index = count ? (count+this.index-1) % count : 0;
					app.$emit('change', app.index);
					app.backing = false;
					setTimeout(() => {this.runing = false;}, 10);
				}, this.runtime);
			},
			next(){
				if(this.runing) return;
				let app = this, count = this.list.length;
				this.nexting = true;
				this.runing = setTimeout(() => {
					app.index = count ? (this.index+1) % count : 0;
					app.$emit('change', app.index);
					app.nexting = false;
					setTimeout(() => {this.runing = false;}, 10);
				}, this.runtime);
			}
        },
        watch: {
			list(val){
				if(this.runing) clearTimeout(this.runing);
				this.backing = this.nexting = this.runing = false;
				this.index = 0;
			},
			speed(val){
				this.runtime = val;
			}
        },
        computed: {
			show_list(){
				var list = [], count = this.list.length;
				var front = this.list[(count+this.index-1)%count];
				for (var i = 0; i < this.this_num; i++) {
					var index = (this.index+i)%count;
					list.push(this.list[index]);
				}
				var after = this.list[(this.index+i)%count];
				return {front: front, list: list, after: after}
			},
        },
        mounted(){
            //渲染完成执行
        }
    }
})